//
//  api.swift
//  daily_count
//
//  Created by 段帅 on 2018/3/29.
//  Copyright © 2018年 Sooc. All rights reserved.
//

import Foundation
import AFNetworking
//开发地址192.168.0.105
//let severseUrl = "http://localhost/"
//阿里云服务器地址
let severseUrl = "http://47.104.22.248/"

//登陆
let  api_login = "duan/login"
//注册
let api_regist = "duan/regist"
//更新
let api_update = "duan/update"
//记录数据
let api_record = "duan/recordDailyBill"
//获取用户信息
let api_getUserMessage = "duan/getUserMessage"
//###每月个人总花费  1级目录
let api_getMonthList = "duan/getMonthList"
//每月个人详细花费  二级目录
let api_getMonthCount = "duan/getMonthCount"
//查询个人账单记录 分页显示
let api_getMyBill = "duan/getMyBill"
//同步个人一级目录数据
let api_updateMonthList = "duan/updateMonthList"
//意见反馈
let api_feedback = "duan/feedback"
//上传图片
let api_upload = "duan/upload"




extension UIViewController {
    
    func Post(url:String,para:[String:Any],sucess:@escaping ([String:Any])->Void){
        let manager = AFHTTPSessionManager()
        manager.responseSerializer = AFHTTPResponseSerializer()
        
        
        manager.post(url, parameters: para, progress: { (pre) in
            
        }, success: { (aaa, responseObject)->Void in
            
            let json = try? JSONSerialization.jsonObject(with: responseObject as! Data, options:JSONSerialization.ReadingOptions.mutableContainers) as! [String:Any]
            
            guard (json != nil) else {
                
//                DSAlert.alert(title: "数据解析出错")
                return
            }
            print(url,json!)
            
            
            
            if json!["code"] as! Int == 0 {
                
                
                sucess(json!)
                
                
            }else{
                
//                DSAlert.alert(title: json!["codeStatus"] as? String)
            }
            
            
            
            
            
        }, failure: { (ssss, error) in
            print(error)
//            DSAlert.alert(title: "网络连接失败")
        })
        
        
    }
    
    
}
